000100******************************************************************
000200*PROGRAM : Register a studen to a class
000300*AUTHOR  : Minh-Tuan Ta
000400******************************************************************
000500 IDENTIFICATION DIVISION.
000600 PROGRAM-ID. REG-A.
000700 ENVIRONMENT DIVISION.
000800     SELECT IOFILE       ASSIGN TO "REGMST.DAT"
000900                         ORGANIZATION    IS INDEXED
001000                         ACCESS          IS RANDOM
001100                         RECORD KEY      IS IO-REG-ID
001200                         FILE STATUS     IS WS-STAT.
001300
001400     SELECT INSCHED      ASSIGN TO "SCHEDMST.DAT"
001500                         ORGANIZATION    IS INDEXED
001600                         ACCESS          IS DYNAMIC
001700                         RECORD KEY      IS SCHED-ID
001800                         FILE STATUS     IS WS-STAT.
001900
002000     SELECT INSTU        ASSIGN TO "STUMST.DAT"
002100                         ORGANIZATION    IS INDEXED
002200                         ACCESS          IS DYNAMIC
002300                         RECORD KEY      IS STU-ID
002400                         ALTERNATE KEY   IS STU-LNAME
002500                                         WITH DUPLICATES
002600                         FILE STATUS     IS WS-STAT.
002700
002800     SELECT INCRS        ASSIGN TO "CRSMST.DAT"
002900                         ORGANIZATION    IS INDEXED
003000                         ACCESS          IS DYNAMIC
003100                         RECORD KEY      IS CRS-ID
003200                         FILE STATUS     IS WS-STAT.
003300
003400     SELECT ININST       ASSIGN TO "INSTMST.DAT"
003500                         ORGANIZATION    IS INDEXED
003600                         ACCESS          IS DYNAMIC
001100                         RECORD KEY    IS INST-ID
                               ALTERNATE KEY IS INST-NAME
                                             WITH DUPLICATES
001200                         FILE STATUS   IS WS-STAT.
003900
004000     SELECT INBLDG       ASSIGN TO "BLDGMST.DAT"
004100                         ORGANIZATION    IS INDEXED
004200                         ACCESS          IS DYNAMIC
004300                         RECORD KEY      IS BLDG-ID
004400                         FILE STATUS     IS WS-STAT.
004500
004600 DATA DIVISION.
004700 FILE SECTION.
004800 FD  IOFILE.
004900 01  IO-REC.
005000     05 IO-REG-ID.
005100         10 IO-TERM     PIC X(6).
005200         10 IO-CRN      PIC 9(4).
005300         10 IO-STU-ID   PIC 9(4).
005400     05  IO-ACTIVE      PIC X.
005500
005600 FD  INSCHED.
005700 01  SCHED-REC.
005800     05  SCHED-ID.
005900         10  SCHED-TERM     PIC X(6).
006000         10  SCHED-CRN      PIC 9(4).
006100     05  SCHED-CRS-ID       PIC X(8).
006200     05  SCHED-BLDG-CODE    PIC X(11).
006300     05  SCHED-INST-ID      PIC 9(3).
006400     05  SCHED-TIME         PIC X(15).
006500     05  SCHED-ACTIVE       PIC X.
006600
006700 FD  INSTU.
006800 01  STU-REC.
006900     05  STU-ID              PIC 9(4).
007000     05  STU-FNAME           PIC X(20).
007100     05  STU-LNAME           PIC X(20).
007200     05  STU-STREET          PIC X(30).
007300     05  STU-ZIP             PIC X(5).
007400     05  STU-ACTIVE          PIC X.
007500
007600 FD  INCRS.
007700 01  CRS-REC.
007800     05  CRS-ID              PIC X(8).
007900     05  CRS-NAME            PIC X(34).
008000     05  CRS-HR              PIC 99.
008100     05  CRS-ACTIVE          PIC X.
008200
008300 FD  ININST.
008400 01  INST-REC.
008500     05  INST-ID             PIC 9(3).
008600     05  INST-NAME           PIC X(20).
008700     05  INST-ACTIVE         PIC X.
008800
008900 FD  INBLDG.
009000 01  BLDG-REC.
009100     05  BLDG-ID             PIC X(11).
009200     05  BLDG-CAPACITY       PIC 9(3).
009300     05  BLDG-ACTIVE         PIC X.
009400
009500 WORKING-STORAGE SECTION.
009600 01  WS-STAT             PIC XX.
009700 01  WS-EOF              PIC X VALUE 'N'.
009800 01  WS-REGKEY.
009900     05  WS-TERM             PIC 9(6).
010000     05  WS-CRN              PIC 9(4).
010100     05  WS-STU-ID           PIC 9(4).
010200 01  WS-ACTIVE           PIC X.
010300 01  WS-DATE.
010400     03  WS-YEAR         PIC 99.
010500     03  WS-MONTH        PIC 99.
010600     03  WS-DAY          PIC 99.
010700 01  WS-ERR              PIC X VALUE 'N'.
010800 01  WS-CONT             PIC X VALUE 'Y'.
       01  WS-ADD              PIC X VALUE 'Y'.
010900
011000 SCREEN SECTION.
011100 01  INPUT-SCRN.
011200         05  BLANK SCREEN.
011300         05  LINE 1  COL 01  VALUE "REGISTRATION".
011400         05          COL 73  PIC 9(2) FROM WS-MONTH.
011500         05          COL 75  VALUE "/".
011600         05          COL 76  PIC 9(2) FROM WS-DAY.
011700         05          COL 78  VALUE "/".
011800         05          COL 79  PIC 9(2) FROM WS-YEAR.
011900         05  LINE 2  COL 37  VALUE "REGISTER".
012000         05  INPUT-TERM-SCRN.
012100             10  LINE 4  COL 20  VALUE "TERM".
012200             10          COL 40  PIC X(6) TO IO-TERM.
012300             10          COL 40  PIC X(6) FROM IO-TERM.
012400         05  INPUT-CRN-SCRN.
012500             10  LINE 5  COL 20  VALUE "CRN".
012600             10          COL 40  PIC 9(4) TO IO-CRN.
012700             10          COL 40  PIC 9(4) FROM IO-CRN.
012800         05  LINE 6  COL 25  VALUE "COURSE ID".
012900         05          COL 40  PIC X(8) FROM SCHED-CRS-ID.
013000         05  LINE 7  COL 25  VALUE "COURSE NAME".
013100         05          COL 40  PIC X(34) FROM CRS-NAME.
013200         05  LINE 8  COL 25  VALUE "CREDIT HR".
013300         05          COL 40  PIC 99  FROM CRS-HR.
013400         05  LINE 9  COL 25  VALUE "BUILDING".
013500         05          COL 40  PIC X(10) FROM SCHED-BLDG-CODE.
013600         05  LINE 10 COL 25  VALUE "CAPACITY".
013700         05          COL 40  PIC 9(3) FROM BLDG-CAPACITY.
013800         05  LINE 11 COL 25  VALUE "INSTRUCTOR".
013900         05          COL 40  PIC X(20) FROM INST-NAME.
014000         05  LINE 12 COL 25  VALUE "TIME".
014100         05          COL 40  PIC X(15) FROM SCHED-TIME.
014200         05  INPUT-STU-ID-SCRN.
014300             10  LINE 13 COL 20  VALUE "STUDENT ID".
014400             10          COL 40  PIC 9(4) TO IO-STU-ID.
014500             10          COL 40  PIC 9(4) FROM IO-STU-ID.
               05  LINE 14     COL 25  VALUE "STUDENT F-NAME".
               05              COL 40  PIC X(20) FROM STU-FNAME.
               05  LINE 15     COL 25  VALUE "STUDENT L-NAME".
               05              COL 40  PIC X(20) FROM STU-LNAME.
               05  LINE 16     COL 25  VALUE "STREET".
               05              COL 40  PIC X(30) FROM STU-STREET.
               05  LINE 17     COL 25  VALUE "ZIP".
               05              COL 40  PIC X(5) FROM STU-ZIP.
014600         05  INPUT-ACTIVE-SCRN.
014700             10  LINE 18 COL 20  VALUE "ACTIVE(Y/N)?".
014800             10          COL 40  PIC X   TO IO-ACTIVE.
014900
015000         05  LINE 20 COL 34  VALUE "(ENTER XXX TO TERM TO EXIT)".
015100
015200 01  ERROR-SCRN.
015300     03  BLANK SCREEN.
015400     03  LINE 12 COL 32 VALUE "ERROR".
015500     03  LINE 14 COL 32 VALUE "FILE STATUS:".
015600     03          COL 46 PIC XX FROM WS-STAT.
015700     03  LINE 16 COL 32 VALUE "CONTINUE(Y/N)?".
015800     03          COL 47 PIC X TO WS-CONT AUTO.
015900
016000 01  SUCCESS-SCRN.
016100     03  BLANK SCREEN.
016200     03  LINE 12 COL 32 VALUE "RECORD ADDED SUCCESSFULLY".
016300     03  LINE 18 COL 32 VALUE "CONTINUE(Y/N)?".
016400     03          COL 47 PIC X TO WS-CONT AUTO.

       01  ADD-SCRN.
           03  BLANK SCREEN.
           03  LINE 12 COL 32 VALUE "DO YOU WANT TO ADD THE RECORD?".
           03  LINE 18 COL 32 VALUE "ADD(Y/N)?".
           03          COL 30 PIC X TO WS-ADD AUTO.

       01  CONT-SCRN.
           03  BLANK SCREEN.
           03  LINE 12 COL 32 VALUE "DO YOU WANT TO CONTINUE?".
           03  LINE 18 COL 32 VALUE "CONTINUE(Y/N)?".
           03          COL 30 PIC X TO WS-CONT AUTO.

016700 PROCEDURE DIVISION.
016800 100-MAIN.
016900     ACCEPT WS-DATE FROM DATE
017000     OPEN    I-O IOFILE
017100             INPUT INSCHED
017200             INPUT INSTU
017300             INPUT ININST
017400             INPUT INCRS
017500             INPUT INBLDG
017600
           MOVE SPACES TO WS-CONT

017700     MOVE SPACES TO IO-TERM
017800     MOVE ZEROS TO IO-CRN
017900     MOVE SPACES TO SCHED-CRS-ID
018000     MOVE SPACES TO CRS-NAME
018100     MOVE ZEROS TO CRS-HR
018200     MOVE SPACES TO SCHED-BLDG-CODE
018300     MOVE ZEROS TO BLDG-CAPACITY
018400     MOVE SPACES TO INST-NAME
018500     MOVE SPACES TO SCHED-TIME
018600     MOVE ZEROS TO IO-STU-ID
018700     MOVE SPACES TO IO-ACTIVE
           MOVE SPACES TO STU-FNAME
           MOVE SPACES TO STU-LNAME
           MOVE SPACES TO STU-ZIP
           MOVE SPACES TO STU-STREET
018800
018900     DISPLAY INPUT-SCRN
019000     ACCEPT INPUT-TERM-SCRN
019100
019200     PERFORM UNTIL IO-TERM = 'XXX' OR WS-CONT = 'N'
019300
019400         ACCEPT INPUT-CRN-SCRN
019500
019600         MOVE IO-TERM TO SCHED-TERM
019700         MOVE IO-CRN TO SCHED-CRN
019800
019900         MOVE 'N' TO WS-ERR
020000
020100         START INSCHED KEY = SCHED-ID
020200             INVALID KEY MOVE 'Y' TO WS-ERR
020300         END-START

               IF (NOT WS-ERR = 'Y')
                   READ INSCHED NEXT RECORD
                   END-READ
               END-IF
020400
020500         IF (NOT WS-ERR = 'Y') AND (SCHED-ACTIVE = 'Y')
020800
020900             MOVE SCHED-CRS-ID TO CRS-ID
021000             MOVE SCHED-INST-ID TO INST-ID
021100             MOVE SCHED-BLDG-CODE TO BLDG-ID
021200
021300             START INCRS KEY = CRS-ID
021400             END-START
021500
021600             READ INCRS NEXT RECORD
021700             END-READ
021800
021900             START ININST KEY = INST-ID
022000             END-START
022100
022200             READ ININST NEXT RECORD
022300             END-READ
022400
022500             START INBLDG KEY = BLDG-ID
022600             END-START
022700
022800             READ INBLDG NEXT RECORD
022900             END-READ
023000
023100             DISPLAY INPUT-SCRN
023200             ACCEPT INPUT-STU-ID-SCRN
023300
023400             MOVE IO-STU-ID TO STU-ID
023500
023600             MOVE 'N' TO WS-ERR
023700
023800             START INSTU KEY = STU-ID
023900                 INVALID KEY MOVE 'Y' TO WS-ERR
024000             END-START

                   IF (NOT WS-ERR = 'Y')
                       READ INSTU NEXT RECORD
                       END-READ
                   END-IF
024100
024200             IF (NOT WS-ERR = 'Y') AND (STU-ACTIVE = 'Y')
024600
024700                 DISPLAY INPUT-SCRN
024800                 ACCEPT INPUT-ACTIVE-SCRN
024900
025000                 MOVE 'N' TO WS-ERR
025100
                       DISPLAY ADD-SCRN
                       ACCEPT ADD-SCRN

                       IF WS-ADD = 'Y'

                           MOVE 'N' TO WS-ERR

                           WRITE IO-REC
                               INVALID KEY MOVE 'Y' TO WS-ERR
                           END-WRITE

                           IF NOT WS-ERR = 'Y'
                               DISPLAY SUCCESS-SCRN
                               ACCEPT SUCCESS-SCRN
                           ELSE
                               DISPLAY ERROR-SCRN
                               ACCEPT ERROR-SCRN
                           END-IF

                       ELSE
                           DISPLAY CONT-SCRN
                           ACCEPT CONT-SCRN
                       END-IF
025500
026300
026400             ELSE
026500                 DISPLAY ERROR-SCRN
026600                 ACCEPT ERROR-SCRN
026700             END-IF
026800         ELSE
026900             DISPLAY ERROR-SCRN
027000             ACCEPT ERROR-SCRN
027100         END-IF
027200
027300         IF NOT WS-CONT = 'N'
027400             MOVE SPACES TO IO-TERM
027500             MOVE ZEROS TO IO-CRN
027600             MOVE SPACES TO SCHED-CRS-ID
027700             MOVE SPACES TO CRS-NAME
027800             MOVE ZEROS TO CRS-HR
027900             MOVE SPACES TO SCHED-BLDG-CODE
028000             MOVE ZEROS TO BLDG-CAPACITY
028100             MOVE SPACES TO INST-NAME
028200             MOVE SPACES TO SCHED-TIME
028300             MOVE ZEROS TO IO-STU-ID
028400             MOVE SPACES TO IO-ACTIVE
                   MOVE SPACES TO STU-FNAME
                   MOVE SPACES TO STU-LNAME
                   MOVE SPACES TO STU-ZIP
                   MOVE SPACES TO STU-STREET

028500
028600             DISPLAY INPUT-SCRN
028700             ACCEPT INPUT-TERM-SCRN
028800         END-IF
028900
029000     END-PERFORM
029100
029200     CLOSE IOFILE
029300     CLOSE INSCHED
029400     CLOSE INSTU
029500     CLOSE ININST
029600     CLOSE INCRS
029700     CLOSE INBLDG
029800
029900     EXIT PROGRAM.
030000
